﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Logistics.DataManage.Local
{
    public class LocalTableTemplate
    {
        IDictionary<String, DataTable> m_Templates;

        internal LocalTableTemplate() { m_Templates = new Dictionary<String, DataTable>(); }

        public DataTable this[String tableName]
        {
            get 
            {
                if (String.IsNullOrEmpty(tableName)) return null;
                DataTable dt=null;
                if (!m_Templates.ContainsKey(tableName.ToLower()))
                {
                    dt = QueryEmptyTable(tableName);
                    m_Templates.Add(tableName.ToLower(), dt);
                }
                else
                    dt = m_Templates[tableName.ToLower()];
                return dt;
            }
        }
        private DataTable QueryEmptyTable(String tableName)
        {
            String sql = "select * from " + tableName+" where 1=2";
            DataSet ds = LocalDb.Handler.ExecuteQuery(sql);
            return ds.Tables[0];
        }

        public DataTable Customers
        {
            get { return this["Customs"]; }
        }
        public DataTable Users
        {
            get { return this["Users"]; }
        }
        public DataTable UsersSites
        {
            get { return this["UsersSites"]; }
        }
        public DataTable SiteInfo
        {
            get { return this["SiteInfo"]; }
        }
        public DataTable NetworkInfo
        {
            get { return this["NetworkInfo"]; }
        }
        public DataTable Rates
        {
            get { return this["Rates"]; }
        }
        public DataTable RatesDetailInfo
        {
            get { return this["RatesDetailInfo"]; }
        }
        public DataTable Routes
        {
            get { return this["Routes"]; }
        }
        public DataTable WaybillInfo
        {
            get { return this["WaybillInfo"]; }
        }
    }
}
